package task;

import org.springframework.cloud.contract.spec.Contract

Contract.make {
    request {
        method 'GET'
        url value(consumer(regex('api/topics/[0-9]+')), producer('api/topics/1'))
    }
    response {
        status 200
        body("""
            {
               "topic": {
                      "id": 1,
                      "programId": 1,
                      "title": "title",
                      "createTime": "2018-01-01 00:00:00.0",
                      "orderNumber": 1,
               },
                "tasks":[{
                        "id":1,
                        "programId": 1,
                        "paperId": 1,
                        "topicId": 1,
                        "orderNumber":1,
                        "content":"content",
                        "createTime":"2018-01-01 00:00:00.0",
                }]
            }
        """)
        bodyMatchers {
            jsonPath('$.[*]',byType())
            jsonPath('$.tasks.[*].id', byRegex(number()))
            jsonPath('$.tasks.[*].programId', byRegex(number()))
            jsonPath('$.tasks.[*].paperId', byRegex(number()))
            jsonPath('$.tasks.[*].topicId', byRegex(number()))
            jsonPath('$.tasks.[*].orderNumber', byRegex(number()))
            jsonPath('$.tasks.[*].createTime', byRegex(nonEmpty()))
            jsonPath('$.tasks.[*].content', byRegex(nonEmpty()))
            jsonPath('$.topic.id', byRegex(number()))
            jsonPath('$.topic.programId', byRegex(number()))
            jsonPath('$.topic.title', byRegex(nonEmpty()))
            jsonPath('$.topic.createTime', byRegex(nonEmpty()))
            jsonPath('$.topic.orderNumber', byRegex(number()))
        }
        headers {
            contentType(applicationJsonUtf8())
        }
    }
}